import request from '../utils/request';
import qs from 'qs';

export async function submitOrder(payload) {
	return request(`/ecs/order/add.action`, {
		method: 'POST',
		headers: {
			'Content-Type': 'application/json'
		},
		body: JSON.stringify(payload)
	})
}

export async function getOrderList(searchParam) {
	return request(`/ecs/order/list.action?${qs.stringify(searchParam, {arrayFormat: 'brackets'})}`, {
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		}
	})
}

export async function getOrderDetail(searchParam) {
	return request(`/ecs/order/detail.action?${qs.stringify(searchParam, {arrayFormat: 'brackets'})}`, {
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		}
	})
}

export async function payDoPay(searchParam) {
	return request(`/ecs/pay/dopay.action`, {
		method: "POST",
		mode: "cors",
		headers: {
			'Accept': 'application/json',
			'Content-Type': 'application/json'
		},
		body: JSON.stringify(searchParam)
	})
}

export async function payAlipay(searchParam) {
	return request(`/ecs/pay/alipay.action`, {
		method: "POST",
		mode: "cors",
		headers: {
			'Accept': 'application/json',
			'Content-Type': 'application/json'
		},
		body: JSON.stringify(searchParam)
	})
}

export async function payWeixin(searchParam) {
	return request(`/ecs/pay/weixin.action`, {
		method: "POST",
		mode: "cors",
		headers: {
			'Accept': 'application/json',
			'Content-Type': 'application/json'
		},
		body: JSON.stringify(searchParam)
	})
}

export async function orderCount(searchParam) {
	return request(`/ecs/order/count.action?${qs.stringify(searchParam, {arrayFormat: 'brackets'})}`, {
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		}
	})
}

export async function paySuccessBack(searchParam) {
	return request(`/ecs/pay/call/back.action`, {
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		}
	})
}
